<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>登录统计</title>
    <link type="text/css" href="../html/cs/default.css" rel="stylesheet"></link>
  </head>
  <body onload="initPage();"> 

<?php
//统计昨天登录的用户数及总登录次数
//set_time_limit(-1);
include 'config.php';

//判断是否已经有昨天的数据
$sql = "select count(login_day) from t_log_login_count where login_day=date_sub(curdate(), interval 1 day) and opflag='countLoginNumbers.php'";
$result= $db->getOne($sql);
if ($result==0)
{
	//取得昨天用户登录总次数(在线时间要大于10秒)
	$sql = "SELECT count(id) FROM `t_log_login` WHERE sumtime>10 and s_time>=concat(date_sub(curdate(), interval 1 day),\" 00:00:00\") and e_time<=concat(date_sub(curdate(), interval 1 day),\" 23:59:59\")order by s_time desc limit 1;";
	$result_id = $db->getOne($sql);
	
	//取得昨天用户登录总人数(即有多少个用户登录过)(在线时间要大于10秒)
	$sql = "SELECT count(distinct(uid)) FROM `t_log_login` WHERE sumtime>10 and s_time>=concat(date_sub(curdate(), interval 1 day),\" 00:00:00\") and e_time<=concat(date_sub(curdate(), interval 1 day),\" 23:59:59\")order by s_time desc limit 1;";
	$result_uid = $db->getOne($sql);
	
	//echo $result_id . "   " . $result_uid;
	
	//将 $result_id 和 $result_uid 写入数据表：t_log_login_count
	$sql = sprintf("insert into t_log_login_count (login_day, total_user, numbers, opflag) values (date_sub(curdate(), interval 1 day), %d, %d, 'countLoginNumbers.php')", $result_id, $result_uid);
	echo date("Y-m-d H:i:s") . " || " . $sql;
	$db->query($sql);
}
?>

<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">统计时间</td>
<td valign="top">登录日期</td>
<td valign="top">登录总人数</td>
<td valign="top">登录总次数</td>
</tr>

<?
//读取 t_log_login_count
$sql = "select optime, login_day, total_user, numbers from t_log_login_count where opflag='countLoginNumbers.php' order by optime DESC;";
$isquery = $db->query($sql);
while ($row = $db->fetch_array($isquery)) {
	      echo "<tr>";
        printf ("<td valign=\"top\">%s</td>", $row["optime"]);
        printf ("<td valign=\"top\">%s</td>", $row["login_day"]);
        printf ("<td valign=\"top\">%s</td>", $row["total_user"]);
        printf ("<td valign=\"top\">%s</td>", $row["numbers"]);
        echo "</tr>";
    }
?>

</body>
</html>
